#include <avr/io.h>
#include <avr/eeprom.h>
#include <math.h>
#include "defines.h"

long  analog2				= 511;
int accel_offset			= 0;		// read the analog acce sensors to get this
long accel_current		        = 0;
float accel                             = 0;		
byte flight_mode			= PRELAUNCH;
float baro_offset                       = 0;

int ledPin =  13;    // LED connected to digital pin 13
int buzzerPin = 4;
int baroPin = 3;
int accelPin = 2;
int acceltest = 11;




void setup() {
  init_ardurocket();
  Serial.begin(57600);
   pinMode(ledPin, OUTPUT); 
   pinMode(buzzerPin, OUTPUT);
   pinMode(acceltest, OUTPUT);
   zero_Baro();
   zero_Accel();
   Serial.println(baro_offset);
   Serial.println(accel_offset);
   
}



void loop()
{
  
  if (flight_mode == PRELAUNCH)
  {
    analog2 = ((float)analogRead(2) * .10) + (analog2 * .90);
    accel_current	= abs((int)analog2 - accel_offset);
    accel = ((float)accel_current* 0.09765625);
   // Serial.println("Waiting for Launch\t");
    Serial.println(accel);
    delay(10);
  }

  

   
  //if(accel >= 1.5 && flight_mode == PRELAUNCH)
  //{
  //  Serial.println("Launch");
  //  flight_mode = LAUNCH;
  //}
 //   if(flight_mode == LAUNCH)
 //   {
      //digitalWrite(ledPin, HIGH);   // set the LED on
//      analog2 = ((float)analogRead(2) * .10) + (analog2 * .90);
//      accel_current	= abs((int)analog2 - accel_offset);
//      accel = ((float)accel_current * 0.09765625);
//      Serial.println(accel);
      //delay(100);                  // wait for a second
     // buzz(4, 1000, 100); // buzz the buzzer on pin 4 at 2500Hz for 500 milliseconds
     //digitalWrite(ledPin, LOW);    // set the LED off
     //delay(100);      // wait for a second
  //   digitalWrite(ledPin, LOW);   // set the LED on
 //  }
 //  digitalWrite(ledPin, HIGH);   // set the LED on
 }
